Page({
  onLoad({
    id
  }) {
    this.getHouseDetail(id)
  },
  async getHouseDetail(id) {
    const {
      code,
      data: visitorList
    } = await wx.http.get(`/visitor/${id}`)
    if (code !== 10000) wx.utils.toast('获取信息失败')
    this.setData({
      ...visitorList
    })
  },
  onShareAppMessage() {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index?id=' + this.data.id,
      imageUrl: 'https://enjoy-plus.oss-cn-beijing.aliyuncs.com/images/share_poster.png',
    }
  },
  onEnd() {
    this.setData({
      validTime: 0
    })
  },
  async onSaveLocal() {
    // 1.根据url地址把图片下载到本地的沙盒中
    const res = await wx.getImageInfo({
      src: this.data.url,
    })
    // 2.把下载到沙盒中的图片文件写入到手机相册中
    await wx.saveImageToPhotosAlbum({
      filePath: res.path,
    })
    wx.utils.toast('保存到本地成功')
  }
})